package com.demo.controller;

import com.bootlever.framework.common.constant.EnumMailType;
import com.bootlever.framework.common.model.BaseMailEntity;
import com.bootlever.framework.core.template.MailTemplate;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;
import java.util.List;

@RestController
@RequestMapping(value = "demo")
public class DemoController {

    @Autowired
    private MailTemplate mailTemplate;

    @RequestMapping(value = "/demoText")
   public String demo() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "测试框架扫包";
   }

   @RequestMapping(value = "/mail")
   public String mail() throws MessagingException {
       BaseMailEntity mailEntity = new BaseMailEntity();
       mailEntity.setTitle("测试邮件");
       mailEntity.setContent("内容xxxxxx");
       mailEntity.setMailType(EnumMailType.TEXT);
       List<String> receivers = Lists.newArrayList();
       receivers.add("893300593@qq.com");
       mailEntity.setReceivers(receivers);
       mailTemplate.send(mailEntity);
       return "发送成功";
   }
}
